<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="UserID" prop="userId">
        <el-input v-model="queryParams.userId" placeholder="请输入用户ID" clearable size="small"
                  @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="CustNo" prop="custNo">
        <el-input v-model="queryParams.custNo" placeholder="请输入客户号" clearable size="small"
                  @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="SerialNo" prop="bindSerialNo">
        <el-input v-model="queryParams.bindSerialNo" placeholder="请输入绑卡流水号" clearable size="small"
                  @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!--      <el-form-item label="AuthorizationCode" prop="authorizationCode">-->
      <!--        <el-input v-model="queryParams.authorizationCode" placeholder="请输入认证码" clearable size="small"-->
      <!--                  @keyup.enter.native="handleQuery" />-->
      <!--      </el-form-item>-->
      <el-form-item label="BankCode" prop="bankCode">
        <el-input v-model="queryParams.bankCode" placeholder="请输入银行编码" clearable size="small"
                  @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!--      <el-form-item label="BankName" prop="bankName">-->
      <!--        <el-input v-model="queryParams.bankName" placeholder="请输入银行名称" clearable size="small"-->
      <!--                  @keyup.enter.native="handleQuery" />-->
      <!--      </el-form-item>-->
      <!-- <el-form-item label="银行卡类型" prop="cardType">
        <el-input v-model="queryParams.cardType" placeholder="请输入银行卡类型" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item label="CardNumber" prop="cardNumber">
        <el-input v-model="queryParams.cardNumber" placeholder="请输入银行卡号" clearable size="small"
                  @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="ExpireDate" prop="expireDate">
        <el-input v-model="queryParams.expireDate" placeholder="请输入有效期" clearable size="small"
                  @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!-- <el-form-item label="国家简码" prop="country">
        <el-input v-model="queryParams.country" placeholder="请输入国家简码" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="国别码" prop="countryCode">
        <el-input v-model="queryParams.countryCode" placeholder="请输入国别码" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="银行卡预留手机号" prop="phoneNumber">
        <el-input v-model="queryParams.phoneNumber" placeholder="请输入银行卡预留手机号" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="生日" prop="birthday">
        <el-input v-model="queryParams.birthday" placeholder="请输入生日" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item label="AccountName" prop="accountName">
        <el-input v-model="queryParams.accountName" placeholder="请输入账户姓名" clearable size="small"
                  @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!-- <el-form-item label="客户编码" prop="customerCode">
        <el-input v-model="queryParams.customerCode" placeholder="请输入客户编码" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item label="Email" prop="email">
        <el-input v-model="queryParams.email" placeholder="请输入邮箱" clearable size="small"
                  @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!-- <el-form-item label="安全码" prop="cvv">
        <el-input v-model="queryParams.cvv" placeholder="请输入安全码" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="PIN" prop="pin">
        <el-input v-model="queryParams.pin" placeholder="请输入PIN" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="OTP" prop="otp">
        <el-input v-model="queryParams.otp" placeholder="请输入OTP" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item label="IsDefault" prop="isDefault">
        <el-select v-model="queryParams.isDefault" placeholder="请选择是否默认卡" clearable size="small">
          <el-option v-for="dict in isDefaultOptions" :key="dict.dictValue" :label="dict.dictLabel"
                     :value="dict.dictValue" />
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="授权码" prop="accessCode">
        <el-input v-model="queryParams.accessCode" placeholder="请输入授权码" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <!-- <el-form-item label="TransAmt" prop="transAmt">
        <el-input v-model="queryParams.transAmt" placeholder="请输入代扣金额" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <!-- <el-form-item label="货币" prop="currency">
        <el-input v-model="queryParams.currency" placeholder="请输入货币" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <!-- <el-form-item label="交易日期" prop="transactionDate">
        <el-input v-model="queryParams.transactionDate" placeholder="请输入交易日期" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item label="TransStatus" prop="transStatus">
        <el-select v-model="queryParams.transStatus" placeholder="请选择交易状态" clearable size="small">
          <el-option v-for="dict in transStatusOptions" :key="dict.dictValue" :label="dict.dictLabel"
                     :value="dict.dictValue" />
        </el-select>
      </el-form-item>
      <el-form-item label="State" prop="state">
        <el-select v-model="queryParams.state" placeholder="请选择状态" clearable size="small">
          <el-option v-for="dict in stateOptions" :key="dict.dictValue" :label="dict.dictLabel"
                     :value="dict.dictValue" />
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="认证Url" prop="authorizationUrl">
        <el-input v-model="queryParams.authorizationUrl" placeholder="请输入认证Url" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery" style="margin-left: 20px;">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                   v-hasPermi="['bizsys:cust_bind_card_log:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
                   v-hasPermi="['bizsys:cust_bind_card_log:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
                   @click="handleDelete" v-hasPermi="['bizsys:cust_bind_card_log:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
                   v-hasPermi="['bizsys:cust_bind_card_log:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="cust_bind_card_logList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" width="100" prop="id" />
      <el-table-column label="UserID" align="center" width="300" prop="userId" />
      <el-table-column label="CustNo" align="center" width="200" prop="custNo" />
      <el-table-column label="SerialNo" align="center" width="240" prop="bindSerialNo" />
      <!-- <el-table-column label="AuthorizationCode" align="center" prop="authorizationCode" /> -->
      <el-table-column label="BankCode" align="center" width="100" prop="bankCode" />
      <el-table-column label="BankName" align="center" width="200" prop="bankName" />
      <el-table-column label="CardType" align="center" width="150" prop="cardType" />
      <el-table-column label="CardNumber" align="center" width="120" prop="cardNumber" />
      <el-table-column label="ExpireDate" align="center" width="100" prop="expireDate" />
      <el-table-column label="Country" align="center" width="100" prop="country" />
      <el-table-column label="CountryCode" align="center" width="120" prop="countryCode" />
      <el-table-column label="PhoneNumber" align="center" width="150" prop="phoneNumber" />
      <el-table-column label="Birthday" align="center" width="120" prop="birthday" />
      <el-table-column label="AccountName" align="center" width="280" prop="accountName" />
      <el-table-column label="CustomerCode" align="center" width="200" prop="customerCode" />
      <el-table-column label="Email" align="center" width="220" prop="email" />
      <!-- <el-table-column label="CVV" align="center" prop="cvv" />
      <el-table-column label="PIN" align="center" prop="pin" />
      <el-table-column label="OTP" align="center" prop="otp" /> -->
      <el-table-column label="IsDefault" align="center" width="100" prop="isDefault" :formatter="isDefaultFormat" />
      <!-- <el-table-column label="AccessCode" align="center" prop="accessCode" /> -->
      <el-table-column label="TransAmt" align="center" width="100" prop="transAmt" />
      <el-table-column label="Currency" align="center" width="100" prop="currency" />
      <el-table-column label="TransactionDate" align="center" width="200" prop="transactionDate" />
      <!-- <el-table-column label="AuthorizationUrl" align="center" prop="authorizationUrl" /> -->
      <el-table-column label="TransStatus" align="center" width="120" prop="transStatus" :formatter="transStatusFormat" />
      <el-table-column label="State" align="center" width="100" prop="state" :formatter="stateFormat" />
      <el-table-column label="Remark" align="center" width="280" prop="remark" />
      <el-table-column label="Operation" align="center" width="140" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                     v-hasPermi="['bizsys:cust_bind_card_log:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                     v-hasPermi="['bizsys:cust_bind_card_log:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                @pagination="getList" />

    <!-- 添加或修改客户绑卡记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="用户ID" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户ID" />
        </el-form-item>
        <el-form-item label="客户号" prop="custNo">
          <el-input v-model="form.custNo" placeholder="请输入客户号" />
        </el-form-item>
        <el-form-item label="绑卡流水号" prop="bindSerialNo">
          <el-input v-model="form.bindSerialNo" placeholder="请输入绑卡流水号" />
        </el-form-item>
        <el-form-item label="认证码" prop="authorizationCode">
          <el-input v-model="form.authorizationCode" placeholder="请输入认证码" />
        </el-form-item>
        <el-form-item label="银行编码" prop="bankCode">
          <el-input v-model="form.bankCode" placeholder="请输入银行编码" />
        </el-form-item>
        <el-form-item label="银行名称" prop="bankName">
          <el-input v-model="form.bankName" placeholder="请输入银行名称" />
        </el-form-item>
        <el-form-item label="银行卡类型" prop="cardType">
          <el-input v-model="form.cardType" placeholder="请输入银行卡类型" />
        </el-form-item>
        <el-form-item label="银行卡号" prop="cardNumber">
          <el-input v-model="form.cardNumber" placeholder="请输入银行卡号" />
        </el-form-item>
        <el-form-item label="有效期" prop="expireDate">
          <el-input v-model="form.expireDate" placeholder="请输入有效期" />
        </el-form-item>
        <el-form-item label="国家简码" prop="country">
          <el-input v-model="form.country" placeholder="请输入国家简码" />
        </el-form-item>
        <el-form-item label="国别码" prop="countryCode">
          <el-input v-model="form.countryCode" placeholder="请输入国别码" />
        </el-form-item>
        <el-form-item label="银行卡预留手机号" prop="phoneNumber">
          <el-input v-model="form.phoneNumber" placeholder="请输入银行卡预留手机号" />
        </el-form-item>
        <el-form-item label="生日" prop="birthday">
          <el-input v-model="form.birthday" placeholder="请输入生日" />
        </el-form-item>
        <el-form-item label="账户姓名" prop="accountName">
          <el-input v-model="form.accountName" placeholder="请输入账户姓名" />
        </el-form-item>
        <el-form-item label="客户编码" prop="customerCode">
          <el-input v-model="form.customerCode" placeholder="请输入客户编码" />
        </el-form-item>
        <el-form-item label="邮箱" prop="email">
          <el-input v-model="form.email" placeholder="请输入邮箱" />
        </el-form-item>
        <el-form-item label="安全码" prop="cvv">
          <el-input v-model="form.cvv" placeholder="请输入安全码" />
        </el-form-item>
        <el-form-item label="PIN" prop="pin">
          <el-input v-model="form.pin" placeholder="请输入PIN" />
        </el-form-item>
        <el-form-item label="OTP" prop="otp">
          <el-input v-model="form.otp" placeholder="请输入OTP" />
        </el-form-item>
        <el-form-item label="是否默认卡" prop="isDefault">
          <el-select v-model="form.isDefault" placeholder="请选择是否默认卡">
            <el-option v-for="dict in isDefaultOptions" :key="dict.dictValue" :label="dict.dictLabel"
                       :value="dict.dictValue"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="授权码" prop="accessCode">
          <el-input v-model="form.accessCode" placeholder="请输入授权码" />
        </el-form-item>
        <el-form-item label="代扣金额" prop="transAmt">
          <el-input v-model="form.transAmt" placeholder="请输入代扣金额" />
        </el-form-item>
        <el-form-item label="货币" prop="currency">
          <el-input v-model="form.currency" placeholder="请输入货币" />
        </el-form-item>
        <el-form-item label="交易日期" prop="transactionDate">
          <el-input v-model="form.transactionDate" placeholder="请输入交易日期" />
        </el-form-item>
        <el-form-item label="交易状态" prop="transStatus">
          <el-select v-model="form.transStatus" placeholder="请选择交易状态">
            <el-option v-for="dict in transStatusOptions" :key="dict.dictValue" :label="dict.dictLabel"
                       :value="dict.dictValue"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="状态" prop="state">
          <el-select v-model="form.state" placeholder="请选择状态">
            <el-option v-for="dict in stateOptions" :key="dict.dictValue" :label="dict.dictLabel"
                       :value="dict.dictValue"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="认证Url" prop="authorizationUrl">
          <el-input v-model="form.authorizationUrl" placeholder="请输入认证Url" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listCust_bind_card_log,
  getCust_bind_card_log,
  delCust_bind_card_log,
  addCust_bind_card_log,
  updateCust_bind_card_log,
  exportCust_bind_card_log
} from "@/api/bizsys/cust_bind_card_log";

export default {
  name: "Cust_bind_card_log",
  components: {},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 客户绑卡记录表格数据
      cust_bind_card_logList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否默认卡字典
      isDefaultOptions: [],
      // 交易状态字典
      transStatusOptions: [],
      // 状态字典
      stateOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        custNo: null,
        bindSerialNo: null,
        authorizationCode: null,
        bankCode: null,
        bankName: null,
        cardType: null,
        cardNumber: null,
        expireDate: null,
        country: null,
        countryCode: null,
        phoneNumber: null,
        birthday: null,
        accountName: null,
        customerCode: null,
        email: null,
        cvv: null,
        pin: null,
        otp: null,
        isDefault: null,
        accessCode: null,
        transAmt: null,
        currency: null,
        transactionDate: null,
        transStatus: null,
        state: null,
        authorizationUrl: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        userId: [{
          required: true,
          message: "用户ID不能为空",
          trigger: "blur"
        }],
        bindSerialNo: [{
          required: true,
          message: "绑卡流水号不能为空",
          trigger: "blur"
        }],
        isDefault: [{
          required: true,
          message: "是否默认卡不能为空",
          trigger: "change"
        }],
        createTime: [{
          required: true,
          message: "创建时间不能为空",
          trigger: "blur"
        }],
        updateTime: [{
          required: true,
          message: "更新时间不能为空",
          trigger: "blur"
        }],
      }
    };
  },
  created() {
    // this.getList();
    this.getDicts("sys_yes_no").then(response => {
      this.isDefaultOptions = response.data;
    });
    this.getDicts("bind_trans_status").then(response => {
      this.transStatusOptions = response.data;
    });
    this.getDicts("state").then(response => {
      this.stateOptions = response.data;
    });
  },
  methods: {
    /** 查询客户绑卡记录列表 */
    getList() {
      this.loading = true;
      listCust_bind_card_log(this.queryParams).then(response => {
        this.cust_bind_card_logList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 是否默认卡字典翻译
    isDefaultFormat(row, column) {
      return this.selectDictLabel(this.isDefaultOptions, row.isDefault);
    },
    // 交易状态字典翻译
    transStatusFormat(row, column) {
      return this.selectDictLabel(this.transStatusOptions, row.transStatus);
    },
    // 状态字典翻译
    stateFormat(row, column) {
      return this.selectDictLabel(this.stateOptions, row.state);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userId: null,
        custNo: null,
        bindSerialNo: null,
        authorizationCode: null,
        bankCode: null,
        bankName: null,
        cardType: null,
        cardNumber: null,
        expireDate: null,
        country: null,
        countryCode: null,
        phoneNumber: null,
        birthday: null,
        accountName: null,
        customerCode: null,
        email: null,
        cvv: null,
        pin: null,
        otp: null,
        isDefault: null,
        accessCode: null,
        transAmt: null,
        currency: null,
        transactionDate: null,
        transStatus: null,
        state: null,
        remark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        authorizationUrl: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加客户绑卡记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getCust_bind_card_log(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改客户绑卡记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateCust_bind_card_log(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCust_bind_card_log(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除客户绑卡记录编号为"' + ids + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return delCust_bind_card_log(ids);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有客户绑卡记录数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return exportCust_bind_card_log(queryParams);
      }).then(response => {
        this.download(response.msg);
      })
    }
  }
};
</script>
